package com.ruoyi.project.business.controller;

import java.util.List;

import com.ruoyi.common.utils.GenerateHtmlUtils;
import com.ruoyi.common.utils.IdUtils;
import org.springframework.data.annotation.Id;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.BusinessAreaType;
import com.ruoyi.project.business.service.IBusinessAreaTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 菜地类型IDController
 * https://syr-farm.oss-cn-beijing.aliyuncs.com/
 * @author ruoyi
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/business/areatype")
public class BusinessAreaTypeController extends BaseController
{
    @Autowired
    private IBusinessAreaTypeService businessAreaTypeService;

    /**
     * 查询菜地类型ID列表
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessAreaType businessAreaType)
    {
        startPage();
        List<BusinessAreaType> list = businessAreaTypeService.selectBusinessAreaTypeList(businessAreaType);
        return getDataTable(list);
    }

    /**
     * 导出菜地类型ID列表
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:export')")
    @Log(title = "菜地类型ID", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessAreaType businessAreaType)
    {
        List<BusinessAreaType> list = businessAreaTypeService.selectBusinessAreaTypeList(businessAreaType);
        ExcelUtil<BusinessAreaType> util = new ExcelUtil<BusinessAreaType>(BusinessAreaType.class);
        return util.exportExcel(list, "areatype");
    }

    /**
     * 获取菜地类型ID详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessAreaTypeService.selectBusinessAreaTypeById(id));
    }

    /**
     * 新增菜地类型ID
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:add')")
    @Log(title = "菜地类型ID", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessAreaType businessAreaType)
    {
        String  fileUrl ="areaType/"+ IdUtils.fastSimpleUUID()+".html";
        GenerateHtmlUtils.genHtml(fileUrl,businessAreaType.getIntroduce());
        businessAreaType.setIntroduce(fileUrl);
        return toAjax(businessAreaTypeService.insertBusinessAreaType(businessAreaType));
    }

    /**
     * 修改菜地类型ID
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:edit')")
    @Log(title = "菜地类型ID", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessAreaType businessAreaType)
    {
        if(businessAreaType.getIntroduce()!=""||!businessAreaType.getIntroduce().isEmpty()){
            String  fileUrl ="areaType/"+ IdUtils.fastSimpleUUID()+".html";
            GenerateHtmlUtils.genHtml(fileUrl,businessAreaType.getIntroduce());
            businessAreaType.setIntroduce(fileUrl);
        }

        return toAjax(businessAreaTypeService.updateBusinessAreaType(businessAreaType));
    }

    /**
     * 删除菜地类型ID
     */
    @PreAuthorize("@ss.hasPermi('business:areatype:remove')")
    @Log(title = "菜地类型ID", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessAreaTypeService.deleteBusinessAreaTypeByIds(ids));
    }

    public static void main(String[] args) {
        GenerateHtmlUtils.genHtml("areaType/1/detail.html","1qqqqqqqq");
    }


}
